package com.shenmazong.lambda;

import java.util.Random;
import java.util.stream.Stream;

/**
 * @program: server-java-demo
 * @description: 演示创建无限流
 * @author: 亮子说编程
 * @create: 2020-10-19 16:33
 **/

public class StreamApiTest2 {

    public static void main(String[] args) {
        //--1
        Stream<Double> doubleStream = Stream.generate(() -> Math.random());
        doubleStream.limit(5).forEach(System.out::println);

        //--2
        Stream<Integer> integerStream = Stream.generate(() -> new Random().nextInt(100));
        integerStream.limit(5).forEach(System.out::println);
    }
}
